<?php

namespace app\api\controller\v1;

use app\common\controller\ApiCommon;
use app\common\model\CourseAdjust;

class CourseAdjusts extends ApiCommon
{
    protected $modelName = "CourseAdjust";


    public function index()
    {
        $this->checkPermission(10);
        return parent::_index();
    }

    public function save()
    {
        $this->checkPermission(1);
        $ret =  parent::_save();
        CourseAdjust::clearCache();
        return $ret;
    }

    public function update($id)
    {
        $this->checkPermission(1);
        $ret = parent::_update($id);
        CourseAdjust::clearCache();
        return $ret;
    }

    public function delete($id)
    {
        $this->checkPermission(1);
        $ret = parent::_delete($id);
        CourseAdjust::clearCache();
        return $ret;
    }

    public function deletes($ids)
    {
        $this->checkPermission(1);
        $ret = parent::_deletes($ids);
        CourseAdjust::clearCache();
        return $ret;
    }


    public function getMap()
    {
        $this->checkPermission(10);
        $cache =  CourseAdjust::getCache();
        $ret = [];
        foreach ($cache as $k => $v) {
            $tmp = [];
            $tmp[] = $k;
            $tmp[] = $v ? $v : null;
            $ret[] = $tmp;
        }
        return json_response($ret);
    }
}
